#!/usr/bin/env node

const inquirer = require('inquirer')
const ejs = require('ejs')
const fs = require('fs')
const path = require('path')

inquirer.prompt([
    {
        type: 'input', // 问题类型
        name: 'name', // 数据属性名
        message: 'project name ?',
        default: 'my-project'
    }
]).then(anwser => {
    const templateDir = path.join(__dirname, "templates") // 获取模板目录
    const aimDir = process.cwd(); // 获取目标目录

    fs.readdir(templateDir, (err, files) => {
        files.forEach((file, index) => {
            ejs.renderFile(path.join(templateDir, file), anwser, (err, result) => {
                if(err) throw err
                fs.writeFileSync(path.join(aimDir, file), result)
            })
        })
    })
})